from django.db import models
from user.models import User  # 导入User模型

# Create your models here.

class Pet(models.Model):
    # 添加用户外键，实现每个宠物属于一个用户
    owner = models.ForeignKey(User, on_delete=models.CASCADE, related_name='pets', verbose_name='宠物主人')
    
    name = models.CharField(max_length=100,verbose_name='宠物名')
    age = models.IntegerField(verbose_name='宠物年龄')
    sex = models.CharField(max_length=100,choices=[('male','male'),('female','female')],verbose_name='宠物性别')
    image = models.ImageField(upload_to='pets/',verbose_name='宠物图片',blank=True, null=True)
    birth_date = models.DateField(null=True,blank=True,verbose_name='宠物出生日期')
    breed = models.CharField(null=True,blank=True,max_length=100,verbose_name='宠物品种')
    weight = models.FloatField(null=True,blank=True,verbose_name='宠物重量')
    height = models.FloatField(null=True,blank=True,verbose_name='宠物高度')
    create_time = models.DateTimeField(auto_now_add=True,verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now=True,verbose_name='更新时间')

    class Meta:
        db_table = 'pets'
        verbose_name = '宠物'
        verbose_name_plural = '宠物'

    def __str__(self):
        return f'{self.name} (主人: {self.owner.username})'